<template>
  <div class="setting">
    <topTitle :titleText="titleText"></topTitle>
    <div class="mainCon">
      <div class="settingBox">
        <p>
          落实实名制定义设置
          <span>(报表配置修改后第二天生效)(配置可输入1-100的数值)</span>
        </p>
        <div class="settingBoxSelect">
          项目总人数低于
          <el-input
            class="input"
            placeholder="请输入内容"
            v-model="days"
            oninput="if(this.value=='00'){this.value='0';}else{this.value=this.value.replace(/[^0-9]/g,'')}"
            clearable
          >
          </el-input>
          <span
            >视为项目未落实实名制；总人数大于等于{{
              oldDays
            }}，视为项目已落实实名制</span
          >
        </div>
        <el-button
          type="primary"
          class="saveBtn"
          :loading="loading"
          v-sdc
          @click="submitSetting('employee_total', days)"
          >保存设置</el-button
        >
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'reportSetting',

  data() {
    return {
      titleText: '报表设置',
      days: 4,
      loading: false,
      oldDays: 0,
    }
  },
  methods: {
    /**
     * @name: 获取之前设置的值
     * @param {type}
     * @Author: luoyong/471826078@qq.com
     */
    getSetting(name) {
      this.axios({
        method: 'post',
        data: { name },
        url: 'api-s/cs/statsparamconfig/findParamByName',
      })
        .then(
          (response) => {
            if (!response.data.hasError) {
              this.days = response.data.result
              this.oldDays = response.data.result
            } else {
            }
          },
          (response) => {}
        )
        .catch((error) => {})
    },
    /**
     * @name: 保存设置
     * @param {type}
     * @Author: luoyong
     */
    submitSetting(name, value) {
      if (value > 100 || value < 1) {
        this.$message.error('请输入1-100范围的数值')
        return
      }
      this.loading = true
      this.axios({
        method: 'post',
        data: { name, value },
        url: 'api-s/cs/statsparamconfig/editParamValue',
      })
        .then(
          (response) => {
            if (!response.data.hasError) {
              this.$message({
                message: '参数设置成功。',
                type: 'success',
              })
              this.getSetting('employee_total')
            } else {
              this.$message({
                message: '参数设置失败。',
                type: 'warning',
              })
            }
            setTimeout(() => {
              this.loading = false
            }, 500)
          },
          (response) => {}
        )
        .catch((error) => {
          this.$message({
            message: '设置失败。',
            type: 'warning',
          })
          setTimeout(() => {
            this.loading = false
          }, 500)
        })
    },
  },
  mounted() {
    this.getSetting('employee_total')
  },
}
</script>
<style lang="less" scoped>
.mainCon {
  padding-left: 24px;
  padding-right: 24px;
  height: calc(100% - 67px);
  overflow-y: auto;
  font-size: 14px;
}
.settingBox {
  p {
    line-height: 40px;
    span {
      display: inline-block;
      color: red;
    }
  }
  &Select {
    margin: 10px 0;
    .el-select {
      margin: 0 8px;
    }
  }
  .el-button {
    height: 36px;
    line-height: 36px;
    padding: 0 15px;
  }
}
.input {
  width: 9%;
}
</style>
